<?php

        #---------------------------------------------------------------
        #  Development source for MHTVS
        #  "The minimal headless TV server for mobile devices"
        #  Copyright (c) 2011, Doug Thompson, perladdict@gmail.com
        #  All rights reserved.
        #
        #  http://code.google.com/p/mhtvs/
        #
        #  View Demo here:
	#  http://www.youtube.com/watch?v=v4M2uVrMrGk
	#
        #  Redistribution and use in source and binary forms, with or
        #  without modification, are permitted provided that the following
        #  conditions are met:
        #
        #    * Redistributions of source code must retain the above
        #      copyright notice, this list of conditions and the
        #      following disclaimer.
        #    * Redistributions in binary form must reproduce the
        #      above copyright notice, this list of conditions and
        #      the following disclaimer in the documentation and/or
        #      other materials provided with the distribution.
        #    * Neither the name of the developer nor the names
        #      of its contributors may be used to endorse or promote
        #      products derived from this software without specific
        #      prior written permission.
        #
        #  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
        #  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
        #  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
        #  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
        #  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
        #  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
        #  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
        #  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
        #  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
        #  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
        #  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
        #  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
        #  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
        #  SUCH DAMAGE.
        #---------------------------------------------------------------


        # The frequencies below were configured for where I am in 
        # Phoenix, Az.  You will probably have to configure your own 
        # list of channel names/freqs for the arrays listed below and 
        # replace them with your local presets.  After you select a 
        # channel you can determine the frequency you will need to 
        # modify in the $tvsettings[freqs] arrayset
        # with this command: 'v4l2-ctl --get-freq' and reassing them.
        # The $tvsettings[channelname] arrayset will probably need to
        # be adjusted to you local presets as well.



$tvsettings = array (
                "channelnum" => array (
                        2 => "2",
                        3 => "3",
                        4 => "4",
                        5 => "5",
                        6 => "6",
                        7 => "7",
                        8 => "8",
                        9 => "9",
                       10 => "10",
                       11 => "11",
                       12 => "12",
                       13 => "13",
                       14 => "14",
                       15 => "15",
                       16 => "16",
                       17 => "17",
                       18 => "18",
                       19 => "19",
                       20 => "20",
                       22 => "22",
                       23 => "23",
                       24 => "24",
                       25 => "25",
                       26 => "26",
                       27 => "27",
                       28 => "28",
                       29 => "29",
                       30 => "30",
                       31 => "31",
                       32 => "32",
                       33 => "33",
                       34 => "34",
                       35 => "35",
                       36 => "36",
                       37 => "37",
                       38 => "38",
                       39 => "39",
                       40 => "40",
                       41 => "41",
                       42 => "42",
                       43 => "43",
                       44 => "44",
                       45 => "45",
                       46 => "46",
                       47 => "47",
                       48 => "48",
                       49 => "49",
                       50 => "50",
                       51 => "51",
                       52 => "52",
                       53 => "53",
                       54 => "54",
                       55 => "55",
                       56 => "56",
                       57 => "57",
                       58 => "58",
                       59 => "59",
                       60 => "60",
                       61 => "61",
                       62 => "62",
                       63 => "63",
                ),
                "freqs" => array (
                        2 => "55.250000",
                        3 => "61.250000",
                        4 => "67.250000",
                        5 => "77.250000",
                        6 => "83.250000",
                        7 => "175.250000",
                        8 => "181.250000",
                        9 => "187.250000",
                       10 => "193.250000",
                       11 => "199.250000",
                       12 => "205.250000",
                       13 => "211.250000",
                       14 => "121.250000",
                       15 => "127.250000",
                       16 => "133.250000",
                       17 => "139.250000",
                       18 => "151.250000",
                       19 => "157.250000",
                       20 => "163.250000",
                       22 => "169.250000",
                       23 => "217.250000",
                       24 => "223.250000",
                       25 => "229.250000",
                       26 => "235.250000",
                       27 => "241.250000",
                       28 => "247.250000",
                       29 => "253.250000",
                       30 => "259.250000",
                       31 => "265.250000",
                       32 => "271.250000",
                       33 => "277.250000",
                       34 => "283.250000",
                       35 => "289.250000",
                       36 => "295.250000",
                       37 => "301.250000",
                       38 => "307.250000",
                       39 => "313.250000",
                       40 => "319.250000",
                       41 => "325.250000",
                       42 => "331.250000",
                       43 => "337.250000",
                       44 => "343.250000",
                       45 => "349.250000",
                       46 => "355.250000",
                       47 => "361.250000",
                       48 => "367.250000",
                       49 => "373.250000",
                       50 => "379.250000",
                       51 => "385.250000",
                       52 => "391.250000",
                       53 => "397.250000",
                       54 => "403.250000",
                       55 => "409.250000",
                       56 => "415.250000",
                       57 => "421.250000",
                       58 => "427.250000",
                       59 => "433.250000",
                       60 => "439.250000",
                       61 => "445.250000",
                       62 => "451.250000",
                       63 => "457.250000"
                ),
                "channelname" => array (
                        2 => "CSPAN",
                        3 => "KTVK",
                        4 => "WGN",
                        5 => "KPHO CBS",
                        6 => "KASW",
                        7 => "COX 7",
                        8 => "KAET PBS",
                        9 => "KUTP MYTV",
                       10 => "KSAZ FOX",
                       11 => "GOVT ACCESS",             
                       12 => "KPNX NBC",
                       13 => "KAZTV",
                       14 => "AZ News Channel",
                       15 => "KNXV ABC",
                       16 => "TBS",
                       17 => "KPPX",
                       18 => "KTVW",                     
                       19 => "KTAZ",                     
                       20 => "KPAZ",                     
                       22 => "LEASED ACCESS",            
                       23 => "DISCOVER",
                       24 => "LIFETIME",
                       25 => "SPIKE TV",
                       26 => "TNT",
                       27 => "FX",
                       28 => "USA",
                       29 => "MTV",
                       30 => "VH1",
                       31 => "SPEED",
                       32 => "ESPN2",
                       33 => "ESPN",
                       34 => "FOX SPORTS",
                       35 => "DISNEY",
                       36 => "CNN",
                       37 => "NICKELODEON",
                       38 => "HLN",
                       39 => "ABC FAMILY",
                       40 => "A AND E",
                       41 => "HGTV",
                       42 => "TLC",
                       43 => "AMC",
                       44 => "GOLF",
                       45 => "TRU TV",
                       46 => "FOOD NETWORK",
                       47 => "FOX NEWS",
                       48 => "TRAVEL CHANNEL",
                       49 => "CMT",
                       50 => "SYFY",
                       51 => "COMEDY CENTRAL",
                       52 => "E ENTERTAINMENT",
                       53 => "CARTOON NETWORK",
                       54 => "KFPH-CA",
                       55 => "GALAVISION",
                       56 => "KPDF AZTECA",   
                       57 => "ANIMAL PLANET",                   
                       58 => "TV LAND",
                       59 => "BET",
                       60 => "BRAVO",
                       61 => "HISTORY",
                       62 => "CNBC",
                       63 => "MSNBC"
                  ),
);

        if ($_POST['chan']) {
                $esc_start = $_POST['chan']; 
                $start = ereg_replace("[^0-9]", "", $esc_start);
                if(isset($tvsettings["freqs"][$start]))   {
                        $newfreq = $tvsettings["freqs"][$start];
                        echo exec("/usr/bin/v4l2-ctl --set-freq $newfreq >/dev/null");
                        #$output = shell_exec('/usr/bin/v4l2-ctl --set-freq $newfreq');
                        #$execstring = "/usr/bin/v4l2-ctl --set-freq $newfreq >/dev/null";
                }
        }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
        <title>android tv server</title>
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
        <style type="text/css">
        body {
                background: #000000;
        }
        .title {
                font-family: Verdana, Helvetica, sans-serif; 
                font-size: 30px; 
                color:#ffffff; 
                padding:4px 4px 4px 4px; 
                margin:4px; 
        }
        </style>
</head>

        <body>
                <form name="chanpost" id="chanpost" action="chanlist.php" method="POST" class="form">
                        <select name="chan" id="select-choice-8" data-native-menu="false" onchange="this.form.submit()" width="300" style="width: 300px">
                        <optgroup label="Channel Selection:">
<?php
                                        foreach ($tvsettings["channelnum"] as $x) {
						$chnum = $tvsettings["channelnum"][$x];
						$chname = $tvsettings["channelname"][$x];
                                                if ($esc_start == $x) {$sel = "selected=\"selected\""; } else { $sel = ""; }
                                                print "\t\t\t\t<option value=\"$chnum\" $sel> $chname </option>\n";
                                        }
?>
                        </optgroup>
                        </select>
                </form>
        </body>
</html>
